Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUnit tree: add option to show/hide namespace nodes; add folding of namespace nodes #1153

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

rowo360
Copy link
Contributor

@rowo360 rowo360 commented Oct 21, 2024

This PR solves issue #1151 and #1152 which both are dealing with the NUnit tree:

  • list fixtures without namespaces
  • fold namespace nodes

From user point of view there's a new submenu item which controls if the namespace nodes are shown or hidden in general.

This menu item is only enabled for the NUnit tree, but disabled if FixtureList or TestList mode is active.

Here's a screenshot: Namespaces are shown on left side, on right side they are hidden

In addition the namespaces are getting folded (if applicable). Here's an example:

From a technical point of view, several aspects had to be taken into account.
The core of this issue is implemented in the class NUnitTreeDisplayStrategy: it's taking care about omitting namespaces and folding of namespaces. I decided not to change the base method MakeTreeNode which is used by all Strategies, but to add the implementation in the NUnitTreeDisplayStrategy class itself. So it's kept independent, avoiding any unintended side effects. However the recursive call to create the nodes for the children are done here, now.
One important line of code is how to detect a namespace reliable - thanks to your hint about SetUpFixtures, I consider this case as well.

When folding the namespaces, I decided to assign the 'deepest' of the folded TestNodes to the resulting TreeNode. All other folded TestNodes will not have a corresponding TreeNode. Some special handling was required for the TreeNode name of folded namespaces. Thanks to the new feature 'Show test duration', the tree node name must be adapted whenever 'Show test duration' is switched on/off and therefore it's not kept untouched after tree node creation. I had the impression that it's difficult to determine the folded name afterwards, so I decided to keep a list of all folded names in the NUnitTreeDisplayStrategy. That list can be used, whenever a tree node name is requested.

VisualState/Settings:
I implemented the ShowNamespace option identically to the Strategy or Grouping option: that means that it's stored in the settings and in the VisualState file. The VisualState file ensures that the same visual tree representation is restored whenever a test project is loaded. And the setting option ensures that the last selected option is applied when opening a project without VisualState file.

And I extended some tests for these new use cases.

@CharliePoole
Copy link
Contributor

FYI, I'm having trouble with this one, in part because there are two different changes and it's hard to pull it apart that way, but mostly because it's very difficult to visualize what it looks like and how it works. I think I'll pull it down and run it.

@CharliePoole
Copy link
Contributor

I built and ran it and now I see what you're doing. There are a few changes I'd like to see, which I'll get into the review after lunch. But here's are a few points in case you are up and about at this time and want something to do...

I think the UI for showing namespace as an additional choice under NUnitTree works. If we succeed in getting rid of the other two strategies, then we can put the option on the main menu as if it were a new strategy. But for the submenu, I'd like to see two radio buttons... Show Namespaces and Hide Namespaces. The verbs make it clearer I think.

For the folding operation, it all looks good except for the XML display. I think it should show the higher level rather than the deepest level. In this case, showing full info seems to trump consistency.

@rowo360
Copy link
Contributor Author

rowo360 commented Oct 22, 2024

Thanks for your feedback - I'll adapt these parts 👍

  • Replace the single submenu item with these two submenu items you mentioned. And only one of them can be checked.
  • Assign the top most TestNode to a folded Namespace node

But I'm already heading to bed now, so I'll start tomorrow :-)
And next time I'll try to prepare a smaller commit, so that the overview is easier!

@CharliePoole
Copy link
Contributor

I couldn't figure out where to add this in the code, so I'll just make a general comment.

I think that the assignment of the deepest node to a folded tree node works in all situations except one: when we display the XML. In that case alone, I'd like to see the XML from the topmost node down. I realize that you have it set up to always use the same tree node for all purposes and this is a possibly messy complication. So if you prefer we can merge it the way it is and revisit at a later time.

Copy link
Contributor

@CharliePoole CharliePoole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. It looks quite good. I've tried to be clear in my comments about which changes I would most strongly like you to do and which are potentially for later, but if not, just ask. And let me know when you feel this is ready to merge.

{
return testNode.Name;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this method is slightly confusing. Up till now, each tree node representeed only one test node. But now, with folding, it can map to multiple namespaces. So... each test node has a name and the tree node may have a combined name. It would be great if this method and the next one could reflect that in some way. GetTreeNodeName and GetTreeNodeDisplayName?

@@ -18,6 +19,8 @@ namespace TestCentric.Gui.Presenters
/// </summary>
public class NUnitTreeDisplayStrategy : DisplayStrategy
{
private IDictionary<TestNode, string> _foldedNodeNames = new Dictionary<TestNode, string>();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you examine whether the base class dictionary, _nodeIndex, which is used for other purposes, could be expanded to serve the purpose of _foldedNodeNames? If not, we could look at it at a later time to decide whether it would simplify things.

this.nunitTreeShowNamespaceMenuItem.Size = new System.Drawing.Size(198, 22);
this.nunitTreeShowNamespaceMenuItem.Tag = "NUNIT_TREE_SHOW_NAMESPACE";
this.nunitTreeShowNamespaceMenuItem.Text = "Namespace";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the text "Show Namespace" so it's clear what it does. I'd actually prefer to see both Show Namespace and Hide Namespace exclusive radio buttons to make it completely clear, but I think we will redo this whole menu thing at least one more time so it could wait.

@rowo360
Copy link
Contributor Author

rowo360 commented Oct 23, 2024

Yes, right! This single menu item looks a little lost - using two menu items is much better.

@rowo360
Copy link
Contributor Author

rowo360 commented Oct 23, 2024

I assign the top most TestNode of all folded Namespace nodes to the TreeNode, now. I'm really fine with this decision!
The 'XML display' now works as you expected.
Some tests start failing after this changes - but that's a good sign that those use cases are covered :-)

@rowo360
Copy link
Contributor Author

rowo360 commented Oct 23, 2024

And I adapted those method names as you suggested:
GetTreeNodeName and GetTreeNodeDisplayName

@rowo360
Copy link
Contributor Author

rowo360 commented Oct 23, 2024

I also had a quick look to the _nodeIndex Dictionary of the base class, which you mentioned.
It might be possible to use it also for getting the combined name of folded namespace nodes, but needs some more investigations. So I prefer to keep the current approach _foldedNodeNames for now.

I will start the commit now, and if everything is ok and succeeds, it's ready to merge from my point of view.

…ssign top most TestNode of folded namespaces to TreeNode
Copy link
Contributor

@CharliePoole CharliePoole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good... I'll merge

@CharliePoole CharliePoole merged commit 1e18cd2 into main Oct 23, 2024
2 checks passed
@CharliePoole CharliePoole deleted the AlternativeNUnitTreeDisplays branch October 23, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants